define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chase/auto_service/index' + location.search,
                    add_url: 'chase/auto_service/add',
                    edit_url: 'chase/auto_service/edit',
                    del_url: 'chase/auto_service/del',
                    multi_url: 'chase/auto_service/multi',
                    table: 'auto_services',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'auto_category_id', title: __('Auto_category_id')},
                        {field: 'category.name', title: __('分类名称')},
                        {field: 'service_name', title: __('Service_name')},
                        // {field: 'service_describe', title: __('Service_describe')},
                        {field: 'service_price', title: __('Service_price'), operate:'BETWEEN'},
                        // {field: 'line_price', title: __('Line_price'), operate:'BETWEEN'},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        category: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chase/auto_service/category' + location.search,
                    add_url: 'chase/auto_service/add',
                    edit_url: 'chase/auto_service/edit',
                    del_url: 'chase/auto_service/del',
                    multi_url: 'chase/auto_service/multi',
                    table: 'auto_services',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                showExport: false,
                commonSearch: false,
                search: false,
                showToggle: false,
                showColumns: false,
                pagination: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'service_id', title: __('服务ID')},
                        {field: 'service.service_name', title: __('服务名称')},
                        {field: 'service.service_price', title: __('服务价格')},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function () {
                                return ` <a href="javascript:;" class="btn btn-xs btn-primary btn-dragsort" title="拖动进行排序"><i class="fa fa-arrows"></i></a> ` +
                                    ` <a href="javascript:;" class="btn btn-xs btn-success btn-editone" title="编辑" >编辑</a> ` +
                                    ` <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="删除" >取消关联</a> `;

                            }}
                    ]
                ]
            });

            $('#toolbar').on('click', '.btn-create', function () {
                var id = $(this).data('id');
                Fast.api.open('/shijiu.php/chase/auto_service/create?category_id='+id, '关联服务')
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        create: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});